clear all


use Full_Data_Set


rename participantid_in_session subj_id_in_session
rename playerid_in_group role
rename playerred_choices red_choices
rename playerblue_choices blue_choices
rename playeraction action
rename playerswitch_point switch_point
rename playerquiz_0 switch_5dollars
rename playernum_errors quiz_errors
rename groupmove_before P2_moved_first
rename subsessionround_number round
rename subsessionurn_round urn_round
rename subsessionnum_before_groups number_first
rename subsessionurn_risk risk_round
rename subsessioncan_observe observable
rename groupid_in_subsession group
rename playerbinary_payment binary_offer
rename playerbinary_choice binary_choice

drop stata_id
egen stata_id = group(participantcode) //ensure uniqueness of stata ID

//Create intuitive treatment labels
gen UQ_session = 0
replace UQ_session = 1 if participantlabel_UQ != .
gen KeZhang_session = 0
replace KeZhang_session = 1 if UQ_session == 1 & sessioncode != "j4wdu04j"

label define KeZhang_sessionlabel 0 "Saito" 1 "KeZhang"
label values KeZhang_session KeZhang_sessionlabel


su participantpayoff, detail
//These payoffs exclude the $10 shot up fee.

gen ordervar = 1
replace ordervar = 0 if sessioncode == "0g48ergl" | sessioncode == "aghfpuh8" | sessioncode == "bmhnfcxn" | sessioncode == "hv1jugjy" | sessioncode == "j4wdu04j"

**************************************************************************************
//TABLE 1: how many subjects per treatment
table KeZhang_session UQ_session ordervar if round == 1
**************************************************************************************

//Generate variables for number of Blue and Red choices
replace blue_choices = -6 + playerchoice_1 + playerchoice_2 + playerchoice_3 + playerchoice_4 + playerchoice_5 + playerchoice_6 if blue_choices == .
replace red_choices = 6- blue_choices if red_choices == .

replace binary_choice = binary_choice -1 //Choice of 0 is play game, choice of 1 is take offer.


//Generate some variables that capture whether pure or mixed strategy was played
gen pure_strat = 0
replace pure_strat = 1 if red_choices == 6 | red_choices ==0
gen pure_red = 0
replace pure_red = 1 if red_choices ==6 
gen mixed_strat = 1 - pure_strat


//Generate treatment labels
gen trip_treat = .
replace trip_treat = 0 if urn_round == 1 & risk_round == 1
replace trip_treat = 1 if urn_round == 1 & risk_round == 0
replace trip_treat = 2 if urn_round == 0 & observable == 1
replace trip_treat = 3 if urn_round == 0 & observable == 0
label define trip_treatlabel 0 "Risk" 1 "Neutral Ambiguity" 2 "Overt Ambiguity" 3 "Malevelent Ambiguity"
label values trip_treat trip_treatlabel

gen KZ_UQ_var = .
replace KZ_UQ_var = 1 if UQ_session == 0
replace KZ_UQ_var = 2 if UQ_session == 1 & KeZhang_session == 0
replace KZ_UQ_var = 3 if KeZhang_session == 1
label define KZ_UQ_varlabel 0 "ANU -- Saito" 1 "UQ -- Saito" 2 "UQ -- KeZhang"
label values KZ_UQ_var KZ_UQ_varlabel


gen true_role = role
replace true_role = 1 if trip_treat == 1 | trip_treat == 0
replace number_first = 6 if trip_treat == 0

gen num_before_int = number_first/6
gen num_before_square = num_before_int*num_before_int

//create a variable, risk_mixer, that is 1 if subject mixed in the risk control
gen risk_mixer_temp = 1 if trip_treat == 0 & mixed_strat == 1
replace risk_mixer_temp = 0 if trip_treat == 0 & mixed_strat == 0
bysort stata_id: egen risk_mixer = max(risk_mixer_temp)
drop risk_mixer_temp

**************************************************************************************
//TABLE 4:  Column 2. 
logit binary_choice c.binary_offer i.mixed_strat i.true_role i.trip_treat if trip_treat>0, cluster(stata_id)
nlcom -_b[_cons]/_b[binary_offer]
nlcom -_b[1.mixed_strat]/_b[binary_offer]
nlcom -_b[2.true_role]/_b[binary_offer]
nlcom -_b[2.trip_treat]/_b[binary_offer]
nlcom -_b[3.trip_treat]/_b[binary_offer]
**************************************************************************************
testnl -_b[_cons]/_b[binary_offer]=16.67
testnl -(_b[_cons]+_b[2.trip_treat])/_b[binary_offer]=16.67
testnl -(_b[_cons]+_b[3.trip_treat])/_b[binary_offer]=16.67


set seed 1
**************************************************************************************
//TABLE 4:  Column 1.
bootstrap, reps(500) cluster(stata_id): qreg switch_point i.mixed_strat i.true_role i.trip_treat i.KeZhang_session if trip_treat>0
**************************************************************************************
test _b[_cons] = 16.67
test _b[_cons] + _b[2.trip_treat] = 16.67
test _b[_cons] + _b[3.trip_treat] = 16.67
**************************************************************************************
//TABLE 5: Column 1
bootstrap, reps(500) cluster(stata_id): qreg switch_point i.mixed_strat i.KeZhang_session if trip_treat == 0 & true_role == 1 & (pure_red == 1 | mixed_strat == 1)
**************************************************************************************

**************************************************************************************
//TABLE 5: Column 2
logit binary_choice c.binary_offer i.mixed_strat i.KeZhang_session if trip_treat ==0 & true_role == 1 & (pure_red == 1 | mixed_strat == 1)
**************************************************************************************

nlcom -_b[_cons]/_b[binary_offer]
testnl -_b[_cons]/_b[binary_offer]=20
nlcom -_b[1.mixed_strat]/_b[binary_offer]

 
*******************************************************
//TABLE 2 is constructed from the following results
**Risk treatment results 
bysort KeZhang_session ordervar UQ_session: su mixed_strat if trip_treat==0 & true_role == 1
bysort UQ_session: su mixed_strat if trip_treat==0 & true_role == 1
bysort KeZhang_session: su mixed_strat if trip_treat==0 & true_role == 1
su mixed_strat if trip_treat==0 & true_role == 1

*******************************************************
**regressions for main tables

label variable num_before_int "$\frac{X}{6}$"
label variable num_before_square "$\frac{X}{6}^2$"
label variable UQ_session "UQ session"
label variable ordervar "Order"
label variable risk_mixer "Mixed in Control"


reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer if trip_treat==1 & true_role == 1 & KeZhang_session==0, cluster(stata_id)
eststo S_N
test 1.risk_mixer#c.num_before_int == 0.risk_mixer#c.num_before_int
test 1.risk_mixer#c.num_before_square == 0.risk_mixer#c.num_before_square
margins , at(num_before_int = (0 1) num_before_square = (0 1) )
reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer if trip_treat==1 & true_role == 1 & KeZhang_session==1, cluster(stata_id)
eststo KZ_N
test 1.risk_mixer#c.num_before_int == 0.risk_mixer#c.num_before_int
test 1.risk_mixer#c.num_before_square == 0.risk_mixer#c.num_before_square
margins , at(num_before_int = (0 1) num_before_square = (0 1) )


reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer if trip_treat==3 & true_role == 1 & KeZhang_session==0, cluster(stata_id)
eststo S_M
test 1.risk_mixer#c.num_before_int == 0.risk_mixer#c.num_before_int
test 1.risk_mixer#c.num_before_square == 0.risk_mixer#c.num_before_square
reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer if trip_treat==3 & true_role == 1 & KeZhang_session==1, cluster(stata_id)
eststo KZ_M
test 1.risk_mixer#c.num_before_int == 0.risk_mixer#c.num_before_int
test 1.risk_mixer#c.num_before_square == 0.risk_mixer#c.num_before_square

reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer if trip_treat==2 & true_role == 1 & KeZhang_session==0, cluster(stata_id)
eststo S_O
test 1.risk_mixer#c.num_before_int == 0.risk_mixer#c.num_before_int
test 1.risk_mixer#c.num_before_square == 0.risk_mixer#c.num_before_square
reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer if trip_treat==2 & true_role == 1 & KeZhang_session==1, cluster(stata_id)
eststo KZ_O
test 1.risk_mixer#c.num_before_int == 0.risk_mixer#c.num_before_int
test 1.risk_mixer#c.num_before_square == 0.risk_mixer#c.num_before_square

**************************************************************************************
//TABLE 3
esttab using main_table.tex, replace cells(b(star fmt(2)) se(par fmt(2))) label varlabels(_cons Constant) mgroups("Neutral" "Malevolent" "Overt", pattern(1 0 1 0 1 0) span prefix(\multicolumn{2}{c}{) suffix(})) mtitle("Saito" "KeZhang" "Saito" "KeZhang" "Saito" "KeZhang") collabels(Mixing)
eststo clear
**************************************************************************************

reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer UQ_session ordervar if trip_treat==1 & true_role == 1 & KeZhang_session==0, cluster(stata_id)
eststo S_N_app
margins , at(num_before_int = (0 1) num_before_square = (0 1) )
reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer ordervar if trip_treat==1 & true_role == 1 & KeZhang_session==1, cluster(stata_id)
eststo KZ_N_app
margins , at(num_before_int = (0 1) num_before_square = (0 1) )

reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer UQ_session ordervar if trip_treat==3 & true_role == 1 & KeZhang_session==0, cluster(stata_id)
eststo S_M
reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer ordervar if trip_treat==3 & true_role == 1 & KeZhang_session==1, cluster(stata_id)
eststo KZ_M

reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer UQ_session ordervar if trip_treat==2 & true_role == 1 & KeZhang_session==0, cluster(stata_id)
eststo S_O
reg mixed_strat c.num_before_int#risk_mixer c.num_before_square#risk_mixer risk_mixer ordervar if trip_treat==2 & true_role == 1 & KeZhang_session==1, cluster(stata_id)
eststo KZ_O

**************************************************************************************
//TABLE 6
esttab using main_table_appendix.tex, replace cells(b(star fmt(2)) se(par fmt(2))) label varlabels(_cons Constant) mgroups("Neutral" "Malevolent" "Overt", pattern(1 0 1 0 1 0) span prefix(\multicolumn{2}{c}{) suffix(})) mtitle("Saito" "KeZhang" "Saito" "KeZhang" "Saito" "KeZhang") collabels(Mixing) interaction(" $\times$ ")
eststo clear
******************************************************************************************

collapse (mean) mixed_strat, by(number_first trip_treat true_role KeZhang_session)


sort number_first

gen trip_treat_plot = trip_treat
replace trip_treat_plot = . if trip_treat == 0
replace trip_treat_plot = 2 if trip_treat == 3
replace trip_treat_plot = 3 if trip_treat == 2
label define trip_treatlabelplot 0 "Risk" 1 "Neutral Ambiguity" 2 "Malevolant Ambiguity" 3 "Overt Ambiguity" 
label values trip_treat_plot trip_treatlabelplot

**********************************************************************************************
//FIGURE 6
	   twoway 	   line mixed_strat number_first if KeZhang_session == 0 & true_role == 1, by(trip_treat_plot, cols(3) legend(pos(6))) lstyle(p1) yscale(r(0 1)) ylabel(0 0.2 0.4 0.6 0.8 1)  || ///
	   line mixed_strat  number_first if  KeZhang_session == 1 & true_role == 1, by(trip_treat_plot, note("")) lcolor(green) xtitle("Amount of uncertainty resolved prior to Row moving, X") ytitle("Proportion of subjects mixing") ///
legend(order(1 "Saito Sessions" 2 "KZ Sessions") pos(6))  ///
       name(strong_ROA_fails_line_two_trip, replace)
*****************************************************************************************	   
	   